package com.cxs.service.impl;

import com.cxs.mapper.NewsCommentMapper;
import com.cxs.model.NewsComment;
import com.cxs.model.NewsCommentExample;
import com.cxs.service.NewsCommentService;
import cxs.utils.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/*
 * @Author:cxs
 * @Date:2021/10/3  11:25
 * @Version 1.0
 * @Motto:放下杂念,只为迎接明天更好的自己
 * */
@Service
public class NewsCommentServiceImpl implements NewsCommentService {
    @Autowired
    private NewsCommentMapper newsCommentMapper;

    @Override
    public List<NewsComment> list(Long nid) {
        NewsCommentExample example = new NewsCommentExample();
        NewsCommentExample.Criteria criteria = example.createCriteria();
        criteria.andNewIdEqualTo(nid);
        return newsCommentMapper.selectByExample(example);
    }

    @Override
    public Result add(NewsComment comment) {
        return newsCommentMapper.insertSelective(comment) > 0 ? Result.OK("评论成功") : Result.failare("评论失败");
    }
}
